#include <iostream>
#include <string>
//#include "CL_News.h"
#include "CL_RSS_Quelle.h"
#include "CL_News_pool.h"
#include<Poco/Timestamp.h>
#include<Poco/DateTimeParser.h>
#include "Poco/DateTimeFormatter.h"

using namespace std;

int main()
{
    CL_News_pool::add_source_url("http://www.spiegel.de/schlagzeilen/index.rss");
    CL_News_pool::add_source_url("http://feeds.reuters.com/Reuters/domesticNews");
    CL_News_pool::add_source_url("http://www.welt.de/?service=Rss");
//    CL_News_pool::add_source_url("http://www.faz.net/s/RubF3CE08B362D244869BE7984590CB6AC1/Tpl~Epartner~SRss_.xml");

    unsigned int t=5;
    for(;;)
    {
        CL_News n = CL_News_pool::old_news_first();
        std::cout<<std::endl;
        std::cout<<"Channel.Titel: "<<n.channel.titel<<std::endl;
        std::cout<<"Channel.url: "<<n.channel.url<<std::endl;
        std::cout<<"Channel.Description: "<<n.channel.description<<std::endl;
        std::cout<<"Channel.language: "<<n.channel.language<<std::endl;
        std::cout<<"Channel.copyright: "<<n.channel.copyright<<std::endl;
        Poco::Timestamp ts=Poco::Timestamp::fromEpochTime(n.channel.pubDate);
        Poco::DateTime dateTime(ts);
        std::cout<<"Channel.pubDate: "<<Poco::DateTimeFormatter::format(dateTime, "%e %b %Y %H:%M")<<std::endl;

        std::cout<<std::endl;
        std::cout<<"Item.Titel: "<<n.newsitem.title<<std::endl;
        std::cout<<"Item.Description: "<<n.newsitem.description<<std::endl;
        std::cout<<"Item.Link: "<<n.newsitem.link<<std::endl;
        std::cout<<"Item.Author: "<<n.newsitem.author<<std::endl;
        {

            Poco::Timestamp ts=Poco::Timestamp::fromEpochTime(n.newsitem.pubDate);
            Poco::DateTime dateTime(ts);
            std::cout<<"Item.pubDate: "<<Poco::DateTimeFormatter::format(dateTime, "%e %b %Y %H:%M")<<std::endl;
        }
        t+=CL_News_pool::get_adaption_rate();
        t=t<1?1:t;
        t=t>100?100:t;
        sleep(t);

    }



//     cout<<endl<<endl<<"Anzahl: "<<anz<<endl;
//    cout << s1 << endl;

    return 0;
}
